package ventanas;



import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JProgressBar;


import java.awt.SystemColor;



public class VentanaSplash extends JFrame {


	private static final long serialVersionUID = 6334817485326808035L;

	/**
	 * Muestra el progreso de carga.
	 */
	public JProgressBar progressBar;

	
	public static void main(String[] args) {
		VentanaSplash splash = new VentanaSplash();

		
		splash.setVisible(true);

		try {

			//Entre cada progreso de carga avanza el progresbar.
			int t = 0;
			int total = 7;

			//Tiempo que espera entre cada progreso
			long sleept = 300L;

			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);

			
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);

			
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);


			
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);


			
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);

		
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);

			
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);



			
			t++;
			splash.progressBar.setValue(t * 100 / total);
			Thread.sleep(sleept);			

			

		} catch (Exception e) {

			e.printStackTrace();

		}
		
		//Se cierra la ventana de carga y se inicia el programa
		splash.dispose();
//		EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				try {
//					VentanaSplash frame = new VentanaSplash();
//					frame.setVisible(true);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		});
	}

	/**
	 * Creacion de la ventana con toda su configuración.
	 */
	public VentanaSplash() {
		//Configuración de la ventana
		getContentPane().setBackground(SystemColor.inactiveCaption);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 440, 286);
		this.setUndecorated(true);
		getContentPane().setLayout(null);

		//Coloca la ventana en el centro de la pantalla.
		Toolkit toolkit = getToolkit();
		Dimension size = toolkit.getScreenSize();
		setLocation(size.width/2-getWidth()/2, size.height/2-getHeight()/2);

		//Creaccion e inserccion de los componenetes de la ventana
		JLabel lblCargando = new JLabel("Cargando...");
		lblCargando.setBounds(10, 224, 96, 21);
		lblCargando.setForeground(SystemColor.inactiveCaptionBorder);
		lblCargando.setFont(new Font("Trebuchet MS", Font.PLAIN, 18));
		getContentPane().add(lblCargando);

		progressBar = new JProgressBar();
		progressBar.setBounds(0, 254, 440, 21);
		progressBar.setStringPainted(true);

		getContentPane().add(progressBar);

		JLabel label = new JLabel("");
		label.setBounds(0, 0, 440, 286);
		label.setIcon(new ImageIcon("imagenesBasicas/splash.jpg"));
		getContentPane().add(label);

	}
}
